package cn.edu.scau.cmi.huangxiyan.client;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ExperimentClient extends Application {

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		String[] args = new String[5];

		primaryStage.setTitle("ExperimentClient");

		Image headImage = new Image("file:lib/head.jpg");
		ImageView imv = new ImageView(headImage);

		Label IDLabel = new Label("学号：201727010407");
		IDLabel.setPrefSize(350, 25);

		Label nameLabel = new Label("姓名：黄浠沿");
		nameLabel.setPrefSize(350, 25);

		VBox stuVBox = new VBox(0);
		stuVBox.setPadding(new Insets(5, 0, 5, 0));
		stuVBox.getChildren().addAll(imv, IDLabel, nameLabel);

		Button button1 = new Button("实验一：接口编程");
		button1.setPrefSize(250, 25);
		button1.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				InterProgrammingClient.main(args);
			}
		});

		Button button2 = new Button("实验二：单例工厂模式（单例模式）");
		button2.setPrefSize(250, 25);
		button2.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new SingletonClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button3 = new Button("实验二：单例工厂模式（多例模式）");
		button3.setPrefSize(250, 25);
		button3.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new MultipletonClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button4 = new Button("实验三：工厂模式（简单工厂方法）");
		button4.setPrefSize(250, 25);
		button4.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new SimpleFactoryMethodClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button5 = new Button("实验三：工厂模式（工厂模式）");
		button5.setPrefSize(250, 25);
		button5.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new FactoryMethodClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button6 = new Button("实验三：工厂模式（抽象工厂模式）");
		button6.setPrefSize(250, 25);
		button6.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new AbstractFactoryClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button7 = new Button("实验四：适配器模式");
		button7.setPrefSize(250, 25);
		button7.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new AdapterClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button8 = new Button("实验五：组合模式（安全组合模式）");
		button8.setPrefSize(250, 25);
		button8.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new SafeCompositeClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button9 = new Button("实验五：组合模式（一致性组合模式）");
		button9.setPrefSize(250, 25);
		button9.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new ConsistentCompositeClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button10 = new Button("实验六：ORM(Hibernate)模式");
		button10.setPrefSize(250, 25);
		button10.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new HibernateClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		Button button11 = new Button("实验七：IOC、DI(Spring)模式");
		button11.setPrefSize(250, 25);
		button11.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				SpringSingletonApplicationContextClient.main(args);
				Platform.runLater(new Runnable() {
					public void run() {
						try {
							new SpringHibernateSessionClient().start(new Stage());
						} catch (Exception e) {
							e.printStackTrace();
						}
					}

				});
			}
		});

		VBox buttonVBox = new VBox(5);
		buttonVBox.setPadding(new Insets(5, 0, 5, 0));
		buttonVBox.getChildren().addAll(button1, button2, button3, button4, button5, button6, button7, button8, button9,
				button10, button11);

		HBox hBox = new HBox(5);
		hBox.setPadding(new Insets(5, 5, 5, 5));
		hBox.getChildren().addAll(stuVBox, buttonVBox);
		Scene scene = new Scene(hBox, 600, 350);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

}
